﻿//    ORMAC
//    A micro-ORM for .NET
//    Copyright (C) <2012>  <A.Ghomi>

//    This library is free software; you can redistribute it and/or
//    modify it under the terms of the GNU Lesser General Public
//    License as published by the Free Software Foundation; either
//    version 2.1 of the License, or (at your option) any later version.

//    This library is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//    Lesser General Public License for more details.

//    You should have received a copy of the GNU Lesser General Public
//    License along with this library; if not, write to the Free Software
//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ORMAC;
using Northwind;

namespace SimpleClassHierarchy1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("This is an ORMAC test application.\nIt will try to connect to Nothrthwind database and list the orders/customers\nThis example shows how to map a simple database relatiopnship to an object relationship\nPress Any key to view the list of orders/customer names form Northwind database:");
            Console.ReadKey();
            //Create the ORMAC reader object
            IReader reader = new OReader();
            //set the connection string
            reader.SetConnectionString("Data Source=localhost;Initial Catalog=Northwind;Integrated Security=True");
            try
            {
                //load the object list from the database
                var orders = reader.LoadFromDatabase<OOrders>();
                foreach (var o in orders)
                {
                    Console.WriteLine(string.Format("Order ID:{0} Date:{1} Customer:{2}",o.OrderID,o.OrderDate,o.Customer.ContactName));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.WriteLine("Press any key to terminate");
            Console.ReadKey();

        }
    }
}
